<template>
	<view>
		<view class="content">
			<view class="merchantName">
				<text>{{merchant_name}}</text>
			</view>
			<view class="mchImage"><image :src="headImg" mode="aspectFit"></image></view>
			<view class="merchantHead">
				<view class=""></view>
				<image class="qRcode" :src="qrCode"></image>
				<view class=""></view>
			</view>
			<view class="merchantName">
				<text style="color:#666666;">收银员姓名:{{ mchName }}</text>
			</view>
			<block v-for="(item, index) in record" :key="index">
				<view class="footer">
					<image :src="qiniu + item.user_logo" mode=""></image>
					<view class="footerInfo1">
						<view>{{ item.nickname }}</view>
						<view style="color:#E44545">￥{{ item.value / 100 }}</view>
					</view>
					<view class="footerInfo2">
						<view>{{ item.phone }}</view>
						<view>{{ item.pay_time }}</view>
					</view>
				</view>
			</block>
		</view>
		<uni-load-more :loadingType="loadingType">下拉显示更多</uni-load-more>
	</view>
</template>

<script>
import eonfox from '@/components/eonfox/eonfox.js';
import merchant from '@/components/eonfox/merchant.js';
import fns from '@/components/eonfox/fns.js';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
var ef = new eonfox();
var downloadTask = null;
var setIntervalID = null;
export default {
	data() {
		return {
			loadingType: 0,
			page: 10,
			//以上为查看更多
			qrCode: '',
			qiniu: '',
			mchName: '',
			headImg: '', //商家头像
			mchId: '', //商家ID
			record: '',
			merchant_name:'', //商家名字
			change:false,
		};
	},
	components: {
		uniLoadMore
	},
	onReachBottom() {
		if (this.loadingType !== 0) {
			return;
		}
		this.loadingType = 1;
		var _this = this;
		var n;
		if (this.loadingType) {
			_this.page = _this.page + 10;
		}
		ef.submit({
			request: {
				s: ['MERCHANTCASHIERSELFORDERLIST', [{ merchant_id: _this.mchId, size: _this.page }]]
			},
			callback: function(data) {
				const dataList = fns.checkError(data, ['s'], function(errno, error) {
					uni.showToast({
						title: error,
						icon: 'none'
					});
				});
				console.log('more', dataList);

				if (dataList.s && dataList.s.data) {
					_this.record = dataList.s.data;
					if (dataList.s.row_count < _this.page) {
						_this.loadingType = 2;
					} else {
						_this.loadingType = 0;
					}
				} else {
					_this.loadingType = 2;
				}
			},
			error(err) {
				fns.err('err', err, 1);
			}
		});
	},
	onShow() {
		console.log('收银员页面，我进来了：：：：：', merchant.prototype.cashierOrderListRefresh);
		var that = this;
		merchant.prototype.cashierOrderListRefresh = false;
		that.getUserInfo();

		if (!setIntervalID) {
			clearInterval(setIntervalID);
		}

		setIntervalID = setInterval(function() {
			if (merchant.prototype.cashierOrderListRefresh) {
				uni.showToast({
					title: '数据有更新，刷新中...',
					icon: 'none'
				});
				console.log('收银员订单页面需要刷新！', merchant.prototype.cashierOrderListRefresh);
				merchant.prototype.cashierOrderListRefresh = false;
				// 获取收银列表
				that.getOrderList();
			}
		}, 10);
	},

	methods: {
		//获取二维码
		getQrCode() {
			console.log('获取二维码');
			var _this = this;
			ef.left_token(function(left_token) {
				//encodeURIComponent  encodeURI
				var qrCode =
					ef.api_server_url +
					'?' +
					encodeURI('data=' + JSON.stringify([['MERCHANTCASHIERSELFQRCODEMONEYPLUS', [{ merchant_id: _this.mchId }]]])) +
					'&token=' +
					left_token +
					'&time=' +
					Date.now();
				_this.qrCode = qrCode;
				console.log('二维码：', qrCode);
			});

			// 获取收银列表
			_this.getOrderList();
		},
		// 获取收银列表
		getOrderList() {
			console.log('getOrderList::::------>获取收银订单列表');
			var _this = this;
			//_this.change = !_this.change;
			ef.submit({
				request: {
					list: ['MERCHANTCASHIERSELFORDERLIST', [{ merchant_id: _this.mchId }]]
				},
				callback(data) {
					var re = fns.checkError(data, ['list'], function(errno, error) {
						uni.showToast({
							title: error,
							icon: 'none'
						});
					});
					console.log(re);
					//收银员，收银记录
					if (re.list && re.list.data) {
						_this.record = re.list.data;
					}
				}
			});
		},

		// 收银员信息
		getUserInfo() {
			var _this = this;
			ef.submit({
				request: {
					config: ['APPLICATIONCONFIG'],
					cashier: ['MERCHANTCASHIERSELF']
					// list:['MERCHANTCASHIERSELFORDERLIST']
				},
				callback(data) {
					var re = fns.checkError(data, ['config', 'cashier'], function(errno, error) {
						uni.showToast({
							title: error,
							icon: 'none'
						});
					});
					console.log(re);
					if (re.config && re.config.qiniu_domain) {
						_this.qiniu = re.config.qiniu_domain;
					}
					//商家ID
					if (re.cashier && re.cashier.merchant_id) {
						_this.mchId = re.cashier.merchant_id;
						console.log('商家ID有更新：', _this.mchId);
						_this.getQrCode();
					}
					//收银员名字
					if (re.cashier && re.cashier.merchant_cashier_name) {
						_this.mchName = re.cashier.merchant_cashier_name;
						_this.headImg = _this.qiniu + re.cashier.merchant_logo;
					}
					//商家名称 
					if(re.cashier && re.cashier.merchant_name){
						_this.merchant_name=re.cashier.merchant_name
					}
				}
			});
		}
	}
};
</script>

<style>
.content {
	display: flex;
	flex-direction: column;
	flex: 1;
	margin: 15px 10upx 0px 10upx;
}

.merchantName {
	/* display: block;
		flex-direction: row;
		flex: 1; */
	text-align: center;
	font-size: 16px;
	margin-bottom: 15upx;
}
.mchImage {
	width: 100%;
	height: 120upx;
	display: flex;
	margin-top: 25upx;
	margin-bottom: 25upx;
}
.mchImage image {
	width: 120upx;
	height: 120upx;
	border-radius: 50%;
	margin: auto;
}

.merchantHead {
	display: flex;
	flex-direction: row;
	flex: 1;
	justify-content: space-between;
	margin-bottom: 40upx;
}

.merchantHead > view {
	width: 50px;
	height: 20px;
}

.merchantHead > view > image {
	width: 50px;
	height: 50px;
}

.qRcode {
	width: 150px;
	height: 150px;
}

.footer {
	height: 70px;
	margin: 5px 0;
	display: flex;
	font-size: 28upx;
	line-height: 60upx;
	border-bottom: 1upx #e1e1e1 solid;
	color: #444444;
}
.footer image {
	width: 80upx;
	height: 80upx;
	border-radius: 50%;
	margin-top: 30upx;
	margin-right: 20upx;
}
.footerInfo1 {
	width: 30%;
	margin-top: 10upx;
	margin-left: 3%;
}
.footerInfo1 view {
	width: 100%;
	height: 35px;
	overflow: hidden;
}
.footerInfo2 {
	width: 50%;
	margin-top: 10upx;
	text-align: right;
}
.footerInfo2 view {
	width: 100%;
	height: 35px;
}
</style>
